﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Principal;
using System.Web;

namespace LeadVinaglue.Repository
{
    public partial class UserTransactionRepository
    {
        LeadVinaglueEntities entities = new LeadVinaglueEntities();

        public List<UserTransaction> GetAll(int userId)
        {
            return (from c in entities.UserTransactions
                    where c.UserId == userId
                    orderby c.TransactionId descending
                    select c).ToList();
        }

        public UserTransaction GetSingle(int id)
        {
            return (from c in entities.UserTransactions where c.TransactionId == id select c).FirstOrDefault();
        }

        public void Create(UserTransaction _object)
        {
            try
            {
                string appname = new EFMembershipProvider().ApplicationName;
                entities.AddToUserTransactions(_object);
                entities.SaveChanges();
            }
            catch
            {
            }
        }

        public void Delete(int id)
        {
            try
            {
                var _object = (from _list in entities.UserTransactions where _list.TransactionId == id select _list).First();
                entities.DeleteObject(_object);
                entities.SaveChanges();
            }
            catch
            {
            }
        }

        public void Save(UserTransaction _object)
        {
            try
            {
                entities.SaveChanges();
            }
            catch
            {
            }
        }
    }
}